/*
 * ConfigurationManager.java is part of htn-example.
 *
 * ConfigurationManager.java is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ConfigurationManager.java is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ConfigurationManager.java.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.htn.telescopes.rtml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Map;
import java.util.SimpleTimeZone;

import ngat.util.ConfigurationProperties;
import ngat.util.NGATProperties;
import ngat.util.NGATPropertyException;
import ngat.util.logging.BogstanLogFormatter;
import ngat.util.logging.ConsoleLogHandler;
import ngat.util.logging.LogManager;
import ngat.util.logging.Logger;
import ngat.util.logging.Logging;


/**
 * This class contains configuration properties.
 */
public class ConfigurationManager implements Logging 
{
	public static final String PROPERTIES_FILENAME = "config_manager.properties";
	
	public static final String CLASS = "ConfigProps";

    public static final int ASYNC_MODE_SOCKET = 1;

    public static final int ASYNC_MODE_RMI = 2;
    
    public static final int ASYNC_MODE_FILE = 3;
	
	/** Default agent name for logging.*/
	public static final String DEFAULT_ID = "TELESCOPE_EA";
    
	/** Default port for DN server. (Listening for messages from UA via SOAP NA).*/
	public static final int    DEFAULT_DN_PORT = 2220;
    
	/** Default port for telemetry server (callbacks from RCS).*/
	public static final int    DEFAULT_TELEMETRY_PORT = 2233;

	/** Default host for telemetry server (callbacks from RCS).*/
	public static final String DEFAULT_TELEMETRY_HOST = "localhost";
    
	/** Default port for OSS. (Ongoing DB insertions).*/
	public static final int    DEFAULT_OSS_PORT = 7940;
   
	/** Default host address for OSS. (Ongoing DB insertions).*/
	public static final String DEFAULT_OSS_HOST = "192.168.1.30";

	/** Default port for SSL ITR.*/
	public static final int    DEFAULT_RELAY_PORT = 7166;

	/** Default host for SSL ITR.*/
	public static final String DEFAULT_RELAY_HOST = "192.168.1.30";

	/** Default port for RCS CTRL. (Status requests).*/
	public static final int    DEFAULT_CTRL_PORT = 9110;
    
	/** Default host address for RCS CTRL. (Status requests).*/
	public static final String DEFAULT_CTRL_HOST = "192.168.1.30";
    
	public static final String DEFAULT_IMAGE_DIR = "/home/estar/nosuchdir";
    
	public static final double DEFAULT_LATITUDE = 0.0;
    
	public static final double DEFAULT_LONGITUDE = 0.0;
    
	public static final double DEFAULT_DOME_LIMIT = 0.0;

	public static final String DEFAULT_FILTER_COMBO = "RATCam-Clear-2";
    
	public static final String DEFAULT_DB_ROOT = "/DEV_Phase2_001";
    
	public static final String DEFAULT_SSL_KEY_FILE_NAME   = "nosuchkeystore.private";
    
	public static final String DEFAULT_SSL_TRUST_FILE_NAME = "nosuchtruststore.public";
    
	public static final String DEFAULT_SSL_KEY_FILE_PASSWORD    = "secret";

    public static final String DEFAULT_OSS_KEY_FILE_NAME   = "nosuchkeystore.private";
    
	public static final String DEFAULT_OSS_TRUST_FILE_NAME = "nosuchtruststore.public";
    
	public static final String DEFAULT_OSS_KEY_FILE_PASSWORD    = "secret";
    
	public static final int    DEFAULT_SSL_FILE_XFER_BANDWIDTH = 50; // kbyte/s
    
	public static final long DEFAULT_TELEMETRY_RECONNECT_TIME = 600*1000L;
    
	public static final String DEFAULT_DOCUMENT_DIR   = "data";
    
	public static final String DEFAULT_EXPIRED_DOCUMENT_DIR   = "expired";
    
	public static final long DEFAULT_EXPIRATOR_POLLING_TIME   = 3600*1000L;
    
	public static final long DEFAULT_EXPIRATOR_OFFSET_TIME    = 1800*1000L;

    public static final String DEFAULT_TAP_PERSISTANCE_FILE_NAME = "availability.dat";
    
    public static final String DEFAULT_ASYNC_OUTPUT_FILE_NAME = "async_output.txt";


	public static final int GROUP_PRIORITY = 5;

	/** Default maximum observation time (mult*expose) (ms).*/
	public static final long DEFAULT_MAX_OBS_TIME = 7200;
    
	/** (Long ISO8601) date formatter.*/
	public static SimpleDateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd 'T' HH:mm:ss z");
    
	/** Date formatter (Long ISO8601).*/
	public static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
    
	/** Date formatter (Medium SOD).*/
	public static SimpleDateFormat mdf = new SimpleDateFormat("ddHHmmss");
    
	/** Date formatter (Day in year).*/
	public static SimpleDateFormat adf = new SimpleDateFormat("yyyyMMdd");
    
	/** UTC Timezone.*/
    public static final SimpleTimeZone UTC = new SimpleTimeZone(0, "UTC");
     
    /** Number formatter for scores.*/
    public static NumberFormat nf;

	/** DN Server port.*/
	protected int dnPort;

	/** Telemetry host i.e. us as seen by RCS.*/
	protected String telemetryHost;

	/** Telemetry port.*/
	protected int telemetryPort;

	/** OSS Server port.*/
	protected int ossPort;
    
	/** OSS host address.*/
	protected String ossHost;
    
	/** True if the OSS requires a secure connection.*/
	protected boolean ossConnectionSecure;

    	protected File   ossKeyFile;
	protected File   ossTrustFile;
	protected String ossPassword;

	/** RCS CTRL Server port.*/
	protected int ctrlPort;
    
	/** RCS CTRL host address.*/
	protected String ctrlHost;
    
	/** RCS SFX Server port.*/
	protected int relayPort;
    
	/** RCS SFX host address.*/
	protected String relayHost;

    protected boolean relaySecure = true;
    
	protected File   relayKeyFile;
	protected File   relayTrustFile;
	protected String relayPassword;

	protected int    transferBandwidth;

        
	/** Base dir where images are placed - ####project-specific.*/
	protected String imageDir;
    
	// Logging.
	protected Logger traceLog;
    
	protected Logger errorLog;
    
	protected Logger connectLog;
    
	/** Identity.*/
	protected String id;

	/** Site latitude (rads).*/
	protected double siteLatitude;

	/** Site longitude (rads).*/
	protected double siteLongitude;

	/** Dome lower limit (rads).*/
	protected double domeLimit;

	/** DB Root name.*/
	protected String dbRootName;

	/**
	 * The directory to store serialized documents in.
	 */
	protected String documentDirectory = new String("data");
    
	/**
	 * The directory to store expired serialized documents in.
	 */
	protected String expiredDocumentDirectory = new String("expired");
	
	/**
	 * The number of milliseconds between runs of the expirator.
	 * @see #DEFAULT_EXPIRATOR_POLLING_TIME
	 */
	protected long expiratorSleepMs = DEFAULT_EXPIRATOR_POLLING_TIME;

	/**
	 * Properties loaded from the tea properties file.
	 */
	protected NGATProperties properties = null;
    
	/** Counts connections from UA(s).*/
	protected int connectionCount;

	/** Holds mapping between filter descriptions and filter combos for PCR.*/
	protected ConfigurationProperties filterMap;

	protected Map requestMap;
    
	protected Map fileMap;

	/** Maps each request to the AgentRequestHandler (ARQ) which will handle its 
	 * <i>update</i> messages from the RCS and <i>abort</i> messages from UA.
	 * Mapping is from the generated ObservationID (oid) to the ARQ.
	 * @see #getUpdateHandler
	 */    
	protected Map agentMap;

	/** Max observing time - ### this should be determined by the OSS via TEST_SCHEDULEImpl.*/
	protected long maxObservingTime;

    /** Which mode we make asynch responses.*/
    protected int asyncResponseMode;

    /** The host where we can lookup the NAR if RMI mode.*/
    protected String narHost;

    /** File where TAP can persist its state.*/
    protected File tapPersistanceFile;
    
    /** File to output asynchronous RTML responses into. */
    protected File asyncOutputFile;

    /** Singleton object */
    private static ConfigurationManager manager;
    
    /** Retrieve a reference to the singleton object. */
    public static ConfigurationManager getManager()
    {
    	if (manager == null)
    	{
    		manager = new ConfigurationManager(PROPERTIES_FILENAME);
    	}
    	
    	return manager;
    }
    
	/** Create a TEA with the supplied ID.*/
	private ConfigurationManager(String file) 
	{

		sdf.setTimeZone(UTC);
		iso8601.setTimeZone(UTC);

		nf = NumberFormat.getInstance();
		nf.setMaximumFractionDigits(6);
		nf.setGroupingUsed(false);

		Logger l = null;
	
		ConsoleLogHandler console = new ConsoleLogHandler(new BogstanLogFormatter());
		console.setLogLevel(ALL);
	
		traceLog   = LogManager.getLogger("TRACE");
		traceLog.setLogLevel(ALL);	
		traceLog.addHandler(console);
	
		// add handler to other loggers used
	
	
		l = LogManager.getLogger("org.estar.tea.DefaultPipelinePlugin");
		l.setLogLevel(ALL);
		l.addHandler(console);
		l = LogManager.getLogger("org.estar.tea.TOCSessionManager");
		l.setLogLevel(ALL);
		l.addHandler(console);
		l = LogManager.getLogger("org.estar.io.eSTARIO");
                l.setLogLevel(ALL);
                l.addHandler(console);

		//TOCSession.initLoggers(console,ALL);
	
		filterMap = new ConfigurationProperties();
        try 
        {
			configure(new File(file));
		} 
        catch (IllegalArgumentException e) 
        {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
        catch (IOException e) 
        {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

    
	/** Sets the incoming request port ###dn is an old name.*/
	public void setDnPort(int p) { this.dnPort = p; }
    
	/** Sets the OSS port.*/
	public void setOssPort(int p) { this.ossPort = p; }
    
	/** Sets the OSS host address.*/
	public void setOssHost(String h) { this.ossHost = h; }

	/** Sets whether the OSS Connection is secure.*/    
	public void setOssConnectionSecure(boolean s) { this.ossConnectionSecure = s; }


	/** Sets the SSL transfer keystore.*/
	public void setOssKeyFile(File k) { ossKeyFile = k; }
    
	/** Sets the SSL transfer trust store.*/
	public void setOssTrustFile(File t) { ossTrustFile = t; };
    
	/** Sets the SSL transfer keypass.*/
	public void setOssPassword(String p) { ossPassword = p; }
    

	/** Sets the RCS CTRL port.*/
	public void setCtrlPort(int p) { this.ctrlPort = p; }
    
	/** Sets the RCS CTRL host address.*/
	public void setCtrlHost(String h) { this.ctrlHost = h; }

	/** Sets the incoming Telemetry port.*/
	public void setTelemetryPort(int p) { this.telemetryPort = p; }

	/** Sets the incoming Telemetry host address (this host as seen by RCS).*/
	public void setTelemetryHost(String h) { this.telemetryHost = h; }

	/** Sets the SSL Fileserver host address.*/
	public void setRelayHost(String r) { this.relayHost = r; }

	/** Sets the SSL Fileserver port.*/
	public void setRelayPort(int p) { this.relayPort = p; }
    
	/** Sets the Base dir where transferred images are placed. ###project-specific*/
	public void setImageDir(String d) { this.imageDir = d; }

    /** Set the NodeAgent Asynch Response Handler host address.*/
    public void setNarHost(String h) { this.narHost = h; }

    public void setAsyncResponseMode(int m) { this.asyncResponseMode = m; }

    /** Set the TAP's persistance file.*/
    public void setTapPersistanceFile(File f) { this.tapPersistanceFile = f; }

	/** Sets the site latitude (rads).*/
	public void setSiteLatitude(double l) { this.siteLatitude = l; }
    
	/** Sets the site longitude (rads).*/
	public void setSiteLongitude(double l) { this.siteLongitude = l; }
    
	/** Sets the dome limit (rads).*/
	public void setDomeLimit(double d) { this.domeLimit = d; }
    
	/** Sets the DB rootname.*/
	public void setDBRootName(String r) { this.dbRootName = r; }
    
	/** Sets the Maximum allowable observation length (ms).*/
	public void setMaxObservingTime(long t) { this.maxObservingTime = t; }
	
	public void setAsyncOutputFile(File f) { this.asyncOutputFile = f; }

	/**
	 * Set the directory to store serialised document in.
	 * @param s A directory.
	 * @see #documentDirectory
	 */
	public void setDocumentDirectory(String s)
	{
		documentDirectory = s;
	}
    
	/**
	 * Set the directory to store expired serialised document in.
	 * @param s A directory.
	 * @see #expiredDocumentDirectory
	 */
	public void setExpiredDocumentDirectory(String s)
	{
		expiredDocumentDirectory = s;
	}
    
	/**
	 * Set how long to sleep between calls to the document exirator.
	 * @param l A long, representing a period in milliseconds.
	 * @see #expiratorSleepMs
	 */
	public void setExpiratorSleepMs(long l)
	{
		expiratorSleepMs = l;
	}

    /** Set whether the image relay is secure.*/
    public void setRelaySecure(boolean r) { this.relaySecure = r;}
    
	/** Sets the SSL transfer keystore.*/
	public void setRelayKeyFile(File k) { relayKeyFile = k; }
    
	/** Sets the SSL transfer trust store.*/
	public void setRelayTrustFile(File t) { relayTrustFile = t; };
    
	/** Sets the SSL transfer keypass.*/
	public void setRelayPassword(String p) { relayPassword = p; }
    
	/** Sets the SSL transfer bandwidth (kbyte/s).*/
	public void setTransferBandwidth(int b) { transferBandwidth = b; }

	/**
	 * Set the tea pipeline properties.
	 * @param file The tea pipeline property file.
	 * @see #properties
	 * @exception FileNotFoundException Thrown if the file doesn't exist. 
	 * @exception IOException Thrown if the load failed.
	 */
	public void configureProperties(File file) throws java.io.FileNotFoundException,
							  java.io.IOException
	{
		properties = new NGATProperties();
		properties.load(file);
	}
    
	/** Returns the Id for this TEA.*/
	public String getId() { return id; }

	/** Returns the DB rootname.*/
	public String getDBRootName() {  return dbRootName; }
    
	/** DN Server port.*/
	public int getDnPort() { return dnPort; }

	/** OSS Server port.*/
	public int getOssPort() { return ossPort; }

	/** Returns whether the OSS Conneciton is secure. */
	public boolean getOssConnectionSecure() { return ossConnectionSecure; }

	/** OSS host address.*/
	public String getOssHost() { return ossHost; }

	/** RCS CTRL Server port.*/
	public int getCtrlPort() { return ctrlPort; }
    
	/** RCS CTRL host address.*/
	public String getCtrlHost() { return ctrlHost; }
    
	/** Telemetry Server port.*/
	public int getTelemetryPort() { return telemetryPort; }
    
	/** Telemetry Server host.*/
	public String getTelemetryHost() { return telemetryHost; }

	/** Base dir where transferred images are placed.*/
	public String getImageDir() { return imageDir; }

	/** Dome limit (rads).*/
	public double getDomeLimit() { return domeLimit; }

	/** Returns the site lattude (rads).*/
	public double getSiteLatitude() { return siteLatitude; }

	/** Returns the site longitude (rads).*/
	public double getSiteLongitude() { return siteLongitude; }

	/** Returns a reference to the filter mapping. ###instrument-specific.*/
	public ConfigurationProperties getFilterMap() { return filterMap; }
    
	public Map getRequestMap() { return requestMap; }
    
	public long getMaxObservingTime() { return maxObservingTime; }

    public int getAsyncResponseMode() { return this.asyncResponseMode; }
    
    public String getNarHost() { return this.narHost; }
    
    public File getAsyncOutputFile() { return this.asyncOutputFile; }

    
	/**
	 * Get the loaded tea properties.
	 * @return The properties.
	 * @see #properties
	 */
	public NGATProperties getProperties() 
	{
		return properties;
	}

	/**
	 * Get an string value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 */
	public String getPropertyString(String key) throws NullPointerException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesString:properties were null.");
		}
		return properties.getProperty(key);
	}

	/**
	 * Get an integer value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 * @exception NGATPropertyException Thrown if the get failed.
	 */
	public int getPropertyInteger(String key) throws NullPointerException, NGATPropertyException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesInteger:properties were null.");
		}
		return properties.getInt(key);
	}
    
	/**
	 * Get an long value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 * @exception NGATPropertyException Thrown if the get failed.
	 */
	public long getPropertyLong(String key) throws NullPointerException, NGATPropertyException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesLong:properties were null.");
		}
		return properties.getLong(key);
	}

	/**
	 * Get an double value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 * @exception NGATPropertyException Thrown if the get failed.
	 */
	public double getPropertyDouble(String key) throws NullPointerException, NGATPropertyException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesDouble:properties were null.");
		}
		return properties.getDouble(key);
	}

	/**
	 * Get an boolean value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 */
	public boolean getPropertyBoolean(String key) throws NullPointerException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesBoolean:properties were null.");
		}
		return properties.getBoolean(key);
	}
    
	/**
	 * Get an class value using the specified key from the loaded tea properties.
	 * @param key The key.
	 * @return The key's value in the properties.
	 * @see #properties
	 * @exception NullPointerException Thrown if the properties are null.
	 * @exception NGATPropertyException Thrown if the get failed.
	 */
	public Class getPropertyClass(String key) throws NullPointerException, NGATPropertyException
	{
		if(properties == null)
		{
			throw new NullPointerException(this.getClass().getName()+
						       ":getPropertiesClass:properties were null.");
		}
		return properties.getClass(key);
	}
    
	/** Load the filter combos from a file.
	 * ### This is camera only for now..
	 * ### Should be replaced with a configured ngat.instrument.Instrument
	 */
	protected void configureFilters(File file) throws IOException {
	
		FileInputStream fin = new FileInputStream(file);
		filterMap.load(fin);
	
	}
    
	/** 
	 * Configure the TEA from a properties file. Load the properties.  
	 * @throws IOException if any IO/file errors.
	 * @throws IllegalArgumentException if any properties missing, wrong, illegal.
	 * @see #properties
	 * @see #configureProperties
	 */
	public void configure(File file) throws IOException, IllegalArgumentException
	{
		ConfigurationProperties config = new ConfigurationProperties();
		config.load(new FileInputStream(file));
		configure(config);
		configureProperties(file);
	}

	/** Configure the TEA from a ConfigurationProperties.
	 * @throws IOException if any IO/file errors.
	 * @throws IllegalArgumentException if any properties missing, wrong, illegal.
	 */
	public void configure(ConfigurationProperties config) throws IOException, IllegalArgumentException 
	{
	
		int dnPort = config.getIntValue("dn.port", DEFAULT_DN_PORT);
	
		int ossPort = config.getIntValue("oss.port", DEFAULT_OSS_PORT);
	
		String ossHost = config.getProperty("oss.host", DEFAULT_OSS_HOST);

		boolean ossSecure = (config.getProperty("oss.secure") != null);
	
		String okf   = config.getProperty("oss.keyfile", DEFAULT_OSS_KEY_FILE_NAME);
		File ossKeyFile = new File(okf);
		
		String otf   = config.getProperty("oss.trustfile", DEFAULT_OSS_TRUST_FILE_NAME);
		File ossTrustFile = new File(otf);
		
		String osspass = config.getProperty("oss.pass",   DEFAULT_OSS_KEY_FILE_PASSWORD);
	
		int ctrlPort = config.getIntValue("ctrl.port", DEFAULT_CTRL_PORT);
	
		String ctrlHost = config.getProperty("ctrl.host", DEFAULT_CTRL_HOST);

		int telPort = config.getIntValue("telemetry.port", DEFAULT_TELEMETRY_PORT);

		String telHost = config.getProperty("telemetry.host", DEFAULT_TELEMETRY_HOST);
	
		String id = config.getProperty("id", DEFAULT_ID);
	
		// Specify as degrees
		double dlat = config.getDoubleValue("latitude", DEFAULT_LATITUDE);
	
		// Specify as degrees
		double dlong = config.getDoubleValue("longitude", DEFAULT_LONGITUDE);
	
		double domeLimit =  config.getDoubleValue("dome.limit", DEFAULT_DOME_LIMIT);
	
		long maxTime = config.getLongValue("max.obs", DEFAULT_MAX_OBS_TIME);
		maxTime = maxTime*1000L;

		String bdir = config.getProperty("base.dir", DEFAULT_IMAGE_DIR);
	
		String dbroot = config.getProperty("db.root", DEFAULT_DB_ROOT);

		String filterMapFileName = config.getProperty("filter.map.file");


		boolean relaySecure = (config.getProperty("relay.secure") != null);

		String rkf   = config.getProperty("ssl.keyfile", DEFAULT_SSL_KEY_FILE_NAME);
		File relayKeyFile = new File(rkf);

		String rtf   = config.getProperty("ssl.trustfile", DEFAULT_SSL_TRUST_FILE_NAME);
		File relayTrustFile = new File(rtf);

		String rpass = config.getProperty("ssl.pass",   DEFAULT_SSL_KEY_FILE_PASSWORD);

		int    band  = config.getIntValue("bandwidth",  DEFAULT_SSL_FILE_XFER_BANDWIDTH);

		String rhost = config.getProperty("relay.host", DEFAULT_RELAY_HOST);

		int    rport = config.getIntValue("relay.port", DEFAULT_RELAY_PORT);

		String documentDirectory        = config.getProperty("document.dir", DEFAULT_DOCUMENT_DIR);
		String expiredDocumentDirectory = config.getProperty("expired.document.dir",
								     DEFAULT_EXPIRED_DOCUMENT_DIR);
		long expiratorSleepMs = config.getLongValue("expirator.sleep", DEFAULT_EXPIRATOR_POLLING_TIME);

		String arm = config.getProperty("async.response.mode", "SOCKET");

		if ("RMI".equals(arm)) {		
		    String nh = config.getProperty("async.response.handler.host", "localhost");
		    setAsyncResponseMode(ASYNC_MODE_RMI);
		    setNarHost(nh);
		} else if
		    ("SOCKET".equals(arm)){
		    setAsyncResponseMode(ASYNC_MODE_SOCKET);	
		} else
		    throw new IllegalArgumentException("Unknown response handler mode; "+arm);

		String tpf = config.getProperty("tap.persistance.file", DEFAULT_TAP_PERSISTANCE_FILE_NAME);
		File tpFile = new File(tpf);
		
		String aof = config.getProperty("async.output.file", DEFAULT_ASYNC_OUTPUT_FILE_NAME);
		File aoFile = new File(aof);
		setAsyncOutputFile(aoFile);
	
		setDnPort(dnPort);
		setOssHost(ossHost);
		setOssPort(ossPort);
		setOssConnectionSecure(ossSecure);
		setOssKeyFile(ossKeyFile);
		setOssTrustFile(ossTrustFile);
		setOssPassword(osspass);
		setCtrlHost(ctrlHost);
		setCtrlPort(ctrlPort);
		setTelemetryHost(telHost);
		setTelemetryPort(telPort);
		setRelayHost(rhost);
		setRelayPort(rport);
		setSiteLatitude(Math.toRadians(dlat));
		setSiteLongitude(Math.toRadians(dlong));
		setDomeLimit(Math.toRadians(domeLimit));
		setImageDir(bdir);
		setDBRootName(dbroot);
	
		setRelaySecure(relaySecure);
		setRelayKeyFile(relayKeyFile);
		setRelayTrustFile(relayTrustFile);
		setRelayPassword(rpass);
		setTransferBandwidth(band);

		setMaxObservingTime(maxTime);

		setDocumentDirectory(documentDirectory);
		setExpiredDocumentDirectory(expiredDocumentDirectory);
		setExpiratorSleepMs(expiratorSleepMs);

		setTapPersistanceFile(tpFile);

		if (filterMapFileName != null) {
			File file = new File(filterMapFileName);		    
			configureFilters(file);		    
		} else {
			throw new IllegalArgumentException("Filter properties file not specified");
		}


	} // [Configure(ConfigProperties)]
}    
